using System;
using System.Collections.Generic;
using Framework.Audio;
using UnityEngine;
using UnityEngine.UI;
using IcecreamView;
using TMPro;

namespace View
{
    public class CommonTipPanel : IcecreamView.IC_AbstractModule
    {

        //[BindUIPath("BG/Title")]
        //private TextMeshProUGUI _title;

        [BindUIPath("BG/Content")]
        private Text _content;

        [BindUIPath("BG/BtnLayout/BackBtn")]
        private Button _backBtn;

        [BindUIPath("BG/BtnLayout/ConfirmBtn")]
        private Button _confirmBtn;

        private Action _onBack;
        private Action _onConfirm;

        public override void OnInitView()
        {   
            this._backBtn.onClick.AddListener(this.OnClickBack);
            this._confirmBtn.onClick.AddListener(this.OnClickConfirm);
        }

        public override void OnOpenView(Dictionary<string, IC_ViewData> parameters)
        {
            AudioManager.Instance.PlaySound("System/btn_3");
            var data = parameters["msg"];
            this._content.text = data.GetValue<string>(0);
            this._onConfirm    = data.GetValue<Action>(1);
            this._onBack       = data.GetValue<Action>(2);
            this._backBtn.gameObject.SetActive(this._onBack != null);
        }

        private void OnClickConfirm()
        {
            AudioManager.Instance.PlaySound("System/ui_btn2");
            this.ViewConnector.CloseView();
            this._onConfirm?.Invoke();
        }

        private void OnClickBack()
        {
            AudioManager.Instance.PlaySound("System/ui_btn2");
            this.ViewConnector.CloseView();
            this._onBack?.Invoke();
        }

    }
}